/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.mochaccino.framework.dbtool.module;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import javax.inject.Named;
import javax.sql.DataSource;
import org.hibernate.cfg.Configuration;

public abstract class DBToolModule extends AbstractModule {

	public static final String        REFERENCE     = "reference";
	public static final String        TARGET        = "target";
	public static final String        CONFIGURATION = "configuration";
	private             DataSource    reference     = null;
	private             Configuration configuration = null;
	private             DataSource    target        = null;

	@Override
	protected void configure() {

	}

	@Provides
	@Named( REFERENCE )
	public final DataSource reference() {
		if ( reference == null ) {
			reference = createReferenceDatasource();
		}
		return reference;
	}

	@Provides
	@Named( TARGET )
	public final DataSource target() {
		if ( target == null ) {
			target = createTargetDatasource();
		}
		return target;
	}

	@Provides
	@Named( CONFIGURATION )
	public final Configuration configuration() {
		if ( configuration == null ) {
			configuration = createConfiguration();
		}
		return configuration;
	}

	protected abstract Configuration createConfiguration();

	protected abstract DataSource createTargetDatasource();

	protected abstract DataSource createReferenceDatasource();
}
